package com.verlet.springbootdemo.simple.nettyrpc.client.codec;

import com.verlet.springbootdemo.simple.nettyrpc.RpcInfo;
import com.verlet.springbootdemo.util.ObjectMapperUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * RpcInfo 编码器
 *
 * @author Verlet
 * @date 2023-08-22 20:08
 */
public class RpcInfoEncoder extends MessageToMessageEncoder<RpcInfo> {

    @Override
    protected void encode(ChannelHandlerContext ctx, RpcInfo msg, List<Object> out) throws Exception {
        String json = ObjectMapperUtils.parseJsonStr(msg);
        if (StringUtils.isNotBlank(json)) {
            out.add(json);
        }
    }
}
